import 'package:flutter_blue_plus_win/flutter_blue_plus_win.dart';
import 'package:flutter_blue_plus_platform_interface/flutter_blue_plus_platform_interface.dart';
extension BluetoothCharacteristicExtension on BluetoothCharacteristic {
  BmBluetoothCharacteristic toProto() {
    return BmBluetoothCharacteristic(
      remoteId: DeviceIdentifier(remoteId.str),
      serviceUuid: serviceUuid,
      // secondaryServiceUuid: secondaryServiceUuid,
      characteristicUuid: characteristicUuid,
      descriptors: [for (final d in descriptors) d.toProto()],
      properties: properties.toProto(),
      primaryServiceUuid: null, // TODO:  API changes
    );
  }
}

extension BluetoothDescriptorExtension on BluetoothDescriptor {
  BmBluetoothDescriptor toProto() {
    return BmBluetoothDescriptor(
      remoteId: DeviceIdentifier(remoteId.str),
      serviceUuid: serviceUuid,
      characteristicUuid: characteristicUuid,
      descriptorUuid: descriptorUuid,
      primaryServiceUuid: null, // TODO:  API changes
    );
  }
}

extension BluetoothServiceExtension on BluetoothService {
  BmBluetoothService toProto() {
    return BmBluetoothService(
      serviceUuid: serviceUuid,
      remoteId: DeviceIdentifier(remoteId.str),
      // isPrimary: isPrimary,
      characteristics: [for (final c in characteristics) c.toProto()],
      // includedServices: [for (final s in includedServices) s.toProto()],
      primaryServiceUuid: null, // TODO:  API changes
    );
  }
}

extension CharacteristicPropertiesExtension on CharacteristicProperties {
  BmCharacteristicProperties toProto() {
    return BmCharacteristicProperties(
      broadcast: broadcast,
      read: read,
      writeWithoutResponse: writeWithoutResponse,
      write: write,
      notify: notify,
      indicate: indicate,
      authenticatedSignedWrites: authenticatedSignedWrites,
      extendedProperties: extendedProperties,
      notifyEncryptionRequired: notifyEncryptionRequired,
      indicateEncryptionRequired: indicateEncryptionRequired,
    );
  }
}
